﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using App2Wpf.ViewModels;

namespace App2Wpf.Views
{
    /// <summary>
    /// PictureBoxUC.xaml 的交互逻辑 直接挂载pictureBox
    /// </summary>
    public partial class PictureBoxUC : UserControl, ICardUC
    {
        public int ID { get; set; }
        public PictureBoxUC(nameip serverinfo)
        {
            InitializeComponent();

            initLoading();

            connectNameip = serverinfo;

        }

        public delegate void closeCardHandle();

        public event closeCardHandle onClose;


        public nameip connectNameip { get; set; }

        public System.Net.IPAddress iPAddress;

        Forms.ViewerF view;

        public void initLoading()
        {
            LoadingG.Visibility = Visibility.Visible;
            FormHost.Visibility = Visibility.Hidden;
        }

        public void StartWork()
        {
            this.iPAddress = System.Net.IPAddress.Parse(connectNameip.ip);
            view = new Forms.ViewerF(iPAddress, connectNameip);

            view.OnConnect += () => {
                Dispatcher.Invoke(new Action(() =>
                { LoadingG.Visibility = Visibility.Collapsed;
                  FormHost.Visibility = Visibility.Visible;
                }));
            };

            cardTitle.Text = view.VirtualDeskForm.Text;
            FormHost.Child = view.VirtualDeskForm.pictureBox1;
        }



      

        private void Close_Button_Click(object sender, RoutedEventArgs e)
        {
            view.session.CloseSession();
            ServiceLocator.rightWrapVM.removeCard(this);
        }
    }
}
